home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / utility / bootany.zip / BOOTANY.ASM < prev    next >
Assembly Source File  |  1990-09-29  |  10KB  |  233 lines

  1. F1_scancode     equ     59
  2. reply_interval  equ     5               ; wait up to 5 seconds for reply
  3.  
  4.                 include bootany.inc
  5.  
  6. code            segment
  7.  
  8.  
  9.                 assume  cs:Code, ds:Code, es:Code, ss:Code
  10.                 org     0
  11.  
  12. bootany         proc    near
  13. ;
  14. ;               Setup the stack
  15. ;
  16.                 mov     AX,CS           ; Get current segment
  17.                 mov     DS,AX           ; Set DS temporarily
  18.                 cli                     ; disable interrupts
  19.                 mov     SS,AX           ; set stack segment
  20.                 mov     SP,NewBootLocation ; initialize stack pointer
  21.                 sti                     ; reenable interrupts
  22. ;
  23. ;               DOS loads this pgm at 0000:7C00. Any boot routine
  24. ;               we call also expects to execute there so the first
  25. ;               exercise is to move this code somewhere else.
  26. ;
  27.                 mov     CX,512          ; bytes to move
  28.                 mov     SI,BootLocation ; Get boot address
  29.                 les     DI,DWORD PTR SecBoot[SI] ; Load ES=07A0,DI=0000
  30.                 rep     movsb           ; Copy to new location
  31.  
  32.                 lea     SI,down+NewBootLocation ; address relocated e.p.
  33.                 jmp     SI
  34.  
  35. down            equ     $
  36. ;
  37. ;               Turn off Numlock (while DS is still 0)
  38. ;
  39.                 mov     AL,DS:[KeyboardFlags] ; Get keyboard flags
  40.                 and     AL,bootOpts.numlockMask[DI] ; Mask numlock flag
  41.                 mov     DS:[KeyboardFlags],AL ; Save keyboard flags
  42. ;
  43. ;               Set up data segment
  44. ;
  45.                 mov     AX,ES           ; Get current segment
  46.                 mov     DS,AX           ; Set data segment
  47. prompt:
  48. ;
  49. ;               Display the menu
  50. ;
  51.                 call    Clear           ; clear the screen
  52.                 mov     CX,max_partitions ; set to max partitions
  53.                 xor     BX,BX           ; set base offset into table
  54.                 mov     SI,-1           ; set index
  55.                 mov     DL,Numeric      ; get first numeric value
  56. promptloop:
  57.                 inc     DL              ; Increment Func Key number
  58.                 cmp     part.partition[BX],0 ; any entry?
  59.                 je      finishPrompt    ; No skip rest
  60.  
  61.                 mov     key,DL          ;  save in message
  62.                 lea     SI,FkeyMsg      ; get msg addr
  63.                 call    Send
  64.  
  65.                 lea     SI,part.text[BX] ; get data addr
  66.                 call    Send
  67.  
  68.                 add     BX,SIZE PartData ; next entry address
  69.                 loop    promptloop
  70. finishPrompt:
  71.                 inc     DL              ; get Func key number
  72.                 mov     basicKey,DL     ; save in message
  73.                 lea     SI,rombasic     ; get msg address
  74.                 call    Send
  75.  
  76.                 mov     AH,01h          ; SetTickCount
  77.                 sub     CX,CX           ; hi-order tick count
  78.                 sub     DX,DX           ; lo-order tick count
  79.                 int     1ah             ; BiosTimerService
  80. ;
  81. ;               Get the reply
  82. ;
  83. reply:
  84.                 mov     AH,1            ; keyboard status
  85.                 int     16h             ; keybd bios service
  86.                 jnz     read_scancode   ; jump if reply
  87.                 sub     AH,AH           ; GetTickCount
  88.                 int     1ah             ; BiosTimerService
  89.                 cmp     DX,192*reply_interval/10 ; check for timeout
  90.                 jb      reply           ; wait for scancode
  91.                 mov     AL,default      ; prior system id
  92.                 cmp     AL,'?'          ; validate key
  93.                 je      error           ; no default
  94.                 jmp     system          ; boot default system
  95. read_scancode:
  96.                 sub     AH,AH           ; read keyboard
  97.                 int     16h             ; keybd bios service
  98.                 sub     AH,F1_scancode-1 ; Turn into index
  99.                 jbe     error           ; Invalid code check
  100.                 mov     AL,AH           ; Copy to AL
  101.                 add     AL,Numeric      ; Make numeric
  102.                 cmp     AL,basicKey     ; max Function key
  103.                 ja      error           ; branch if bad response
  104.                 jne     system          ; if not basic, branch
  105.                 int     18h             ; else invoke rom basic
  106. error:
  107.                 jmp     prompt          ; reissue prompt
  108. ;
  109. ;               A valid function key was depressed (or defaulted)
  110. ;               Attempt to boot the corresponding partition.
  111. ;
  112. system:
  113.                 mov     key,AL          ; save function key number
  114.                 dec     AL              ; subtract for offset
  115.                 sub     AL,Numeric      ; convert to binary
  116.                 mov     AH,SIZE PartData ; Get entry size
  117.                 mul     AH              ; Get offset
  118.                 mov     BX,AX           ; move to usable register
  119.                 mov     AL,part.partition[BX] ; get partition number
  120.                 dec     AL              ; subtract for offset
  121.                 mov     BL,SIZE PartitionEntry ; Get entry size
  122.                 mul     BL              ; Get offset
  123.                 mov     BX,AX           ; move to usable register
  124. ;
  125. ;               Only boot bootable partitions.
  126. ;
  127. check:
  128.                 cmp     partitionTable.BootIndicator[BX],0
  129.                                         ; bootable partition?
  130.                 je      error           ; No - display menu again
  131. ;
  132. ;               Read in and validate the partition's boot sector.
  133. ;
  134. select:
  135.                 mov     DH,partitionTable.BeginHead[BX]
  136.                                         ; head from partition table
  137.                 mov     DL,80h          ; drive 0
  138.                 mov     CL,partitionTable.BeginSector[BX]
  139.                                         ; sector from table
  140.                 mov     CH,partitionTable.BeginCyl[BX]
  141.                                         ; cylinder from partition table
  142.                 push    BX              ; Save index
  143.                 les     BX,DWORD PTR PrimBoot ; address primary boot loc
  144.                 mov     AX,201h         ; function, # of sectors
  145.                 int     13h             ; read system boot record
  146.                 pop     BX              ; Restore index
  147.                 jc      error           ; exit if error
  148.                 cmp     word ptr ES:510,0aa55h ; test signature
  149.                 jne     error           ; reprompt if invalid
  150. ;
  151. ;               Hide the previously booted partition and unhide the
  152. ;               partition to be booted.
  153. ;
  154.                 mov     AL,key          ; get depressed key number
  155.                 mov     DL,default      ; get last booted
  156.                 mov     default,AL      ; save Function key number
  157.                 mov     DI,defaultPart  ; Get default index
  158.                 mov     defaultPart,BX  ; Save new index
  159.                 cmp     DL,'?'          ; any default?
  160.                 je      SetCurrent      ; no - Only set up current
  161.                 cmp     AL,DL           ; current = default?
  162.                 je      EndBoot         ; yes - skip reset
  163.                 mov     AL,partitionTable.SystemId[DI]
  164.                                         ; Get partition type
  165.                 mov     partitionTable.BootIndicator[DI],AL
  166.                                         ; Save as boot indicator
  167.                 mov     partitionTable.SystemId[DI],80h
  168.                                         ; Booted part. won't see it now
  169. SetCurrent:
  170.                 mov     AL,partitionTable.BootIndicator[BX]
  171.                                         ; Get partition type
  172.                 mov     partitionTable.SystemId[BX],AL
  173.                                         ; Put it where it belongs
  174.                 mov     partitionTable.BootIndicator[BX],80h
  175.                                         ; Show partition is bootable
  176. ;
  177. ;               Clear the screen, update the boot sector with new
  178. ;               values, and give control to the partitions boot program
  179. ;
  180. EndBoot:
  181.                 call    Clear           ; clear the screen
  182.                 mov     AX,301h         ; write sector
  183.                 les     BX,DWORD PTR SecBoot ; buffer address
  184.                 mov     CX,1            ; cylinder 0, sector 1
  185.                 sub     DH,DH           ; head 0
  186.                 mov     DL,80h          ; drive 0
  187.                 int     13h             ; replace boot record
  188.                 cli                     ; disable interrupts
  189.                 mov     SI,BootLocation ; get address of area read
  190.                 jmp     SI              ; enter second level boot
  191. Clear:
  192.                 mov     AH,15           ; return current video mode
  193.                 int     10h             ; bios service
  194.                 sub     AH,AH           ; set mode
  195.                 int     10h             ; reset video mode
  196.                 ret
  197. Send:
  198.                 cld                     ; reset direction flag
  199.                 lodsb                   ; load argument from string
  200.                 test    AL,80h          ; test for end of string
  201.                 pushf                   ; save flags
  202.                 and     AL,7fh          ; insure valid character
  203.                 mov     AH,14           ; write tty
  204.                 int     10h             ; bios video service
  205.                 popf                    ; restore flags
  206.                 jz      Send            ; do until end of string
  207.                 ret                     ; return to caller
  208.  
  209. SecBoot         dw      0,NewBootSeg    ; ES=7A0, BX=0
  210. PrimBoot        dw      0,BootSeg       ; ES=7C0, BX=0
  211. FkeyMsg         db      13,10,'F'
  212. key             db      'X . . .',+0A0h
  213. rombasic        db      13,10,'F'
  214. basicKey        db      'X . . . ROM BASIC',13,10,10
  215.                 db      'Default: F'
  216. default         db      '?',' '+80h
  217. defaultPart     dw      -1
  218. used            equ     $ - bootany
  219. clearAmt        equ     DataAddr - used ; Assembly error if code too big
  220.  
  221.                 db      clearAmt dup(0) ; clear rest of record
  222.  
  223. part            PartData max_partitions dup(<>)
  224.  
  225. bootOpts        BootData <>
  226.  
  227. partitionTable  PartitionEntry 4 dup(<>)
  228.  
  229. bootany         endp
  230. code            ends
  231.  
  232.                 end
  233.